# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=valhalla
pkgver=3.1.4
pkgrel=15
pkgdesc="Open Source Routing Engine for OpenStreetMap"
url="https://valhalla.readthedocs.io/"
# s390x blocked by prime_server
# ppc64le, riscv64 blocked by luajit
arch="all !ppc64le !s390x !riscv64"
license="MIT"
depends_dev="
	boost-dev
	curl-dev
	gtest-dev
	libspatialite-dev
	luajit-dev
	prime_server-dev
	protobuf-dev
	python3-dev
	sqlite-dev
	zeromq-dev
	zlib-dev
	"
makedepends="$depends_dev
	cmake
	"
subpackages="$pkgname-dev $pkgname-doc"
source="https://dev.alpinelinux.org/archive/valhalla/valhalla-$pkgver.tar.gz
	0001-libvalhalla-configuring.patch
	gcc13.patch
	"
builddir="$srcdir/$pkgname"

_disturl="dev.alpinelinux.org:/archive/$pkgname/"

snapshot() {
	clean
	deps
	mkdir -p "$srcdir" && cd "$srcdir"
	git clone https://github.com/valhalla/valhalla --recursive
	cd valhalla && git checkout $pkgver && cd -
	tar czvf $SRCDEST/$pkgname-$pkgver.tar.gz valhalla
	rsync --progress -La $SRCDEST/$pkgname-$pkgver.tar.gz $_disturl
}

build() {
	export CXXFLAGS="$CXXFLAGS -Wno-deprecated-declarations"
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_STANDARD=17 \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=TRUE \
		-DENABLE_WERROR=OFF \
		-DENABLE_TOOLS=OFF \
		-DENABLE_DATA_TOOLS=OFF \
		-DENABLE_SERVICES=OFF \
		-DENABLE_HTTP=ON \
		-DENABLE_PYTHON_BINDINGS=OFF \
		-DENABLE_CCACHE=OFF \
		-DENABLE_COVERAGE=OFF \
		-DENABLE_COMPILER_WARNINGS=ON \
		-DENABLE_SANITIZERS=OFF \
		-DENABLE_ADDRESS_SANITIZER=OFF \
		-DENABLE_UNDEFINED_SANITIZER=OFF \
		-DENABLE_TESTS=ON \
		-DENABLE_SINGLE_FILES_WERROR=OFF \
		-DENABLE_BENCHMARKS=OFF \
		-DENABLE_THREAD_SAFE_TILE_REF_COUNT=OFF \
		-DINSTALL_GTEST=OFF
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
94bda83499d975bf8cb04db4bb226e081b03174bdbff2cdf79570632999d89c72772fb6b366a64615398fad0b684a3803612a8550bc3f324979127dcafc2828d  valhalla-3.1.4.tar.gz
7bec6abe6d203cf654f32b841268f99a83cb29eb300499bb19f7eacf22730511b3337116d9acedbc2cad33455f5759f9248d5ba1a15ed5e7ec49dddfce4e35ce  0001-libvalhalla-configuring.patch
4448f0966f3c8e66403a485e44b3cab7bad0fefae9300db6dc8f96852cdf8e769528b6cd890d533b0991c12c69d3eb7ba111f2f61fd8f1da3b7a12a2f4d6b690  gcc13.patch
"
